package com.tedu.controller;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.tedu.model.Category;
import com.tedu.model.Product;
import com.tedu.service.ICategoryService;
import com.tedu.service.IProductService;

@Controller
public class IndexController {
	private IProductService productService;
	private ICategoryService categoryService;

	@Resource
	public void setProductService(IProductService productService) {
		this.productService = productService;
	}
	
	@Resource
	public void setCategoryService(ICategoryService categoryService) {
		this.categoryService = categoryService;
	}

	//新项目
	@RequestMapping(value="/index.html", method=RequestMethod.GET)
	public String index(Model model){
		List<Product> discountProducts = productService.listAllProductOfDiscount();
		List<Product> hotSaleProducts = productService.listAllProductByFeature(2);
		List<Product> featuredProducts = productService.listAllProductByFeature(3);
		List<Category> categoryList = categoryService.list();
        Collections.shuffle(discountProducts);
        Collections.shuffle(hotSaleProducts);
        Collections.shuffle(featuredProducts);
		model.addAttribute("hotSaleProducts",hotSaleProducts);
		model.addAttribute("featuredProducts",featuredProducts);
		model.addAttribute("discountProducts",discountProducts);
		model.addAttribute("categoryList", categoryList);
		model.addAttribute("reqSource", "index");
		return "client/index";
	}
	
}
